package model;

import java.util.ArrayList;

public class Edge {
	public String label;
	public String id;

	public Node sourceNode;
	public Node targetNode;

	/**
	 * attributes of edges
	 */
	public ArrayList<Attribute> attributes = new ArrayList<Attribute>();

	public int getSourceId() {
		String sId = sourceNode.id;
		String[] splits = sId.split("_");
		return Integer.parseInt(splits[2]);
	}

	public int getTargetId() {
		String sId = targetNode.id;
		String[] splits = sId.split("_");
		return Integer.parseInt(splits[2]);
	}
	
	public boolean satisfy(QueryEdge qEdge) {
		if(qEdge.label !=null && qEdge.label.compareTo(this.label) !=0){
			return false;
		}
		ArrayList<QueryAttribute> predicate = qEdge.queryAttributes;
		if (predicate == null || predicate.size() == 0) {
			return true;
		}
		for (int i = 0; i < predicate.size(); i++) {
			QueryAttribute qAttr = predicate.get(i);
			if (qAttr == null) {
				continue;
			} else {
				if (qAttr.predicateType == 0) {
					if (qAttr.predicatedValue
							.compareTo(attributes.get(i).value) != 0) {
						return false;
					}
				}
				if (qAttr.predicateType == 1) {
					if (qAttr.predicatedValue
							.compareTo(attributes.get(i).value) >= 0) {
						return false;
					}
				}
				if (qAttr.predicateType == 2) {
					if (qAttr.predicatedValue
							.compareTo(attributes.get(i).value) <= 0) {
						return false;
					}
				}

			}
		}
		return true;
	}

}